<%-- 
    Document   : index
    Created on : Jan 31, 2013, 1:58:28 AM
    Author     : amr
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
    <head>
        <script>
            function deleteThisID(id)
            {
                window.location.assign("DeleteBook.jsp?deletedBookISBN="+id)
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <center>
        <form action="books.jsp">
            <input type="text" name="searchkey" value="" /><input type="submit" value="search" />
            <a href="Add new book.jsp">Add new book</a>
        </form>
        <sql:setDataSource 
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3308/mydb"
            user="root" password="123456"
            var="books" 
            scope="session" />
        <c:if test="${param.searchKey eq null}">
            <sql:query var="am" dataSource="${books}">
                SELECT * FROM book
            </sql:query>
        </c:if>
        <c:if test="${param.searchkey ne null}">
            <sql:query var="am" dataSource="${books}">
                SELECT * FROM book where title like '%${param.searchkey}%'
            </sql:query>
        </c:if>
        <table>
            <c:forEach items="${am.rows}" var="row">
                <tr>
                    <td><c:out value="${row.isbn}"/></td>        
                    <td><a href="bookDetails.jsp?bookISBN=${row.isbn}"><c:out value="${row.title}"/></a></td>
                    <td>by <c:out value="${row.auther}"/></td>
                    <td><c:out value="${row.category}"/></td>
                    <td><input type="submit" name="delete" value="delete"  id="${row.isbn}" onclick="deleteThisID(id)"/></td>
                </tr> 
            </c:forEach> 
        </table> 
    </center>
</body>
</html>
